var instance = axios.create({}) // 这样创建出来的 只需要：

instance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';


function _alert(msg) {
    var _timeout = arguments[1] ? arguments[1] : 1;
    layer.msg(msg,{time:1000});
    setTimeout(function () {

    },1000);
}

function ajaxPostSubmit(url,data,msg,cb1) {
    layer.confirm('是否'+msg+'？',function(index){
        layer.close(index);
        var params = new URLSearchParams();
        $.each(data,function (k,v) {
            params.append(k,v);
        })
        instance.post(url,params)
            .then(function (response) {
                var data = response.data;
                if(data.status == 1){
                    cb1(data);
                }else{
                    _alert(data.msg);
                }
            })
            .catch(function (error) {
                console.log(error)
            });
        return false;
    });
}

function my_sort(obj,url){
    var value = obj.value;
    var rsort = obj.getAttribute('rsort');
    if(rsort == value){
        return false;
    }
    if(value.length > 150){
        layer.msg('最多只能输入150字符', {
            time: 1000 //2秒关闭（如果不配置，默认是3秒）
        });
        return false;
    }
    instance.post(url,{value:value})
        .then(function (response) {
            var data = response.data;
            if(data.status == 1){
                obj.setAttribute('rsort',value);
            }
            layer.msg(data.msg, {
                time: 500 //2秒关闭（如果不配置，默认是3秒）
            });
        })
        .catch(function (error) {
            console.log(error)
        });
    return false;
}

function opmsg(url, msg){
    layer.confirm('你确定要'+msg+'吗？', {icon: 3}, function (index) {
        layer.alert('正在处理…', {icon: 5});
        $.get(url, function(data){
            if(data.status == 1){
                layer.alert(data.info, {icon: 6});
                if(typeof(data.url)=="undefined"){
                    window.location.reload();
                }else{
                    window.location.href=data.url;
                }
            }else{
                layer.alert(data.info, {icon: 5});
            }

        });
    });
}